package com.example.demo.modules.redis.service.impl;

import com.example.demo.modules.redis.service.redisService;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Set;

@Service
public class redisServiceImpl implements redisService {

    @Resource
    private RedisTemplate redisTemplate;

    @Override
    public String save(String key, String value) {
        redisTemplate.opsForValue().set(key, value);
        return "成功";
    }

    @Override
    public String delete(String key) {
        Set keys = redisTemplate.keys(key);
        if(CollectionUtils.isNotEmpty(keys)){
            redisTemplate.delete(keys);
            return "成功";
        }else{
            return "没有找到key";
        }
    }
}
